import * as React from 'react';
export const schema = {
    type: "page",
    title: "申请提现",
    body: {
        type: "crud",
        api: "/api/cash/project",
        columnsTogglable: false,
        primaryField: 'project_id',
        bulkActions: [
                    {
                        type: "button",
                        label: "申请提现",
                        actionType: "dialog",
                        level: "info",
                        dialog: {
                            title: "申请提现",
                            size: 'lg',
                            body: {
                                type: "form",
                                api: 'post:/api/cash',
                                controls: [
                                    {
                                        children: (props, path) => {
                                            console.info(props);
                                            const { rows } = props.data;
                                            const { cashInfo }= props.locals;
                                            if (!rows || rows.length <= 0 ) return null;
                                            let total = {settled: 0.0, unsettled_count: 0, unsettled: 0.0};
                                            return (
                                                <div key={1} className="table-responsive bg-white b-a m-t-md" style={{marginBottom: '10px', overflow: 'hidden'}}>
                                                    <table className="table table-striped m-b-none">
                                                        <thead>
                                                        <tr>
                                                            <th style={{width: 60}}>编号</th>
                                                            <th>项目名称</th>
                                                            <th>已提总额</th>
                                                            <th>未结算单数</th>
                                                            <th>未结算总额</th>
                                                            <th>本次所需手续费</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        {rows.map((p, index) => {
                                                            total.settled = parseFloat(total.settled) + parseFloat(p.settled);
                                                            total.unsettled = parseFloat(total.unsettled) + parseFloat(p.unsettled);
                                                            total.unsettled_count = parseInt(total.unsettled_count) + parseInt(p.unsettled_count);
                                                            return (
                                                            <tr key={index}>
                                                                <td>{index+1}</td>
                                                                <td>{p.project_info.name}</td>

                                                                <td>{p.settled}</td>
                                                                <td>{p.unsettled_count}</td>
                                                                <td>{p.unsettled}</td>
                                                                <td> - </td>
                                                            </tr>
                                                        )})}
                                                        {
                                                            rows.length > 1 ?
                                                                (
                                                                    <tr key={999}>
                                                                        <td>总计</td>
                                                                        <td> - </td>
                                                                        <td>{total.settled}</td>
                                                                        <td>{total.unsettled_count}</td>
                                                                        <td>{total.unsettled}</td>
                                                                        <td> - </td>
                                                                    </tr>
                                                                )
                                                                :
                                                                null
                                                        }
                                                        </tbody>
                                                    </table>
                                                    <div className="form-group form-item form-item-static" style={{ marginTop: "10px"}}>
                                                        <label className="col-sm-5 control-label">户名</label>
                                                        <div className="col-sm-7" style={{color: "#3399FF", fontWeight: "bold"}}>
                                                            <div className="form-control-static">{cashInfo.bank_card_account}</div>
                                                        </div>
                                                    </div>
                                                    <div className="form-group form-item form-item-static">
                                                        <label className="col-sm-5 control-label">账号</label>
                                                        <div className="col-sm-7" style={{color: "#3399FF", fontWeight: "bold"}}>
                                                            <div className="form-control-static">{cashInfo.bank_card_num}</div>
                                                        </div>
                                                    </div>
                                                    <div className="form-group form-item form-item-static" >
                                                        <label className="col-sm-5 control-label">开户银行</label>
                                                        <div className="col-sm-7" style={{color: "#3399FF", fontWeight: "bold"}}>
                                                            <div className="form-control-static">{cashInfo.bank_company}</div>
                                                        </div>
                                                    </div>
                                                    <div className="form-group form-item form-item-static" >
                                                        <label className="col-sm-5 control-label">开户支行</label>
                                                        <div className="col-sm-7" style={{color: "#3399FF", fontWeight: "bold"}}>
                                                            <div className="form-control-static">{cashInfo.bank_branch}</div>
                                                        </div>
                                                    </div>
                                                    <div className="form-group form-item form-item-static" >
                                                        <label className="col-sm-5 control-label">开户行地址</label>
                                                        <div className="col-sm-7" style={{color: "#3399FF", fontWeight: "bold"}}>
                                                            <div className="form-control-static">{cashInfo.bank_card_open_addr}</div>
                                                        </div>
                                                    </div>
                                                </div>
                                            )
                                        }
                                    },
                                    {
                                        type: "textarea",
                                        label: "提款用途",
                                        name: "apply_msg",
                                    }
                                ]
                            }
                        }
                    },
            ],
        columns: [
            {
                label: "项目名称",
                name: "project_info.name"
            },
            {
                label: "已提总额",
                name: "settled"
            },
            {
                label: "未结算单数",
                name: 'unsettled_count'
            },
            {
                label: "未结算总额",
                name: 'unsettled'
            },
            {
                label: "本次所需手续费",
                name: 'transfer_fee',
            },
        ]
    }
};
